package site.jlopen.controller.modules;

import java.util.List;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import site.jlopen.entity.BaseResponse;
import site.jlopen.entity.job.JobRunStatusVo;
import site.jlopen.entity.job.TaskLogVo;
import site.jlopen.service.BaseService;

@RestController
@RequestMapping("/jobTask")
public class JobTaskController extends BaseService {

	@GetMapping("/state")
	public BaseResponse<String> state(Long projectId, Long flowId) {
		return jobTaskService.getJobStatus(projectId, flowId);
	}

	@PostMapping("/startJob")
	public BaseResponse<String> startJob(Long projectId, Long flowId,
			@RequestParam(value="graphNodeId", required = false) String graphNodeId,
			Integer jobType
			) {
		return jobTaskService.startJob(projectId, flowId, graphNodeId, jobType);
	}

	@PostMapping("/stopJob")
	public BaseResponse<String> stopJob(Long projectId, Long flowId) {
		return jobTaskService.stopJob(projectId, flowId);
	}

	@GetMapping("/loadTaskLogs")
	public BaseResponse<List<TaskLogVo>> loadTaskLogs(Long projectId, Long flowId) {
		List<TaskLogVo> list =  jobTaskService.getTaskLogs(projectId, flowId);
		return new BaseResponse<List<TaskLogVo>>().success("success").setData(list);
	}

	@GetMapping("/taskLog")
	public BaseResponse<List<String>> taskLog(Long projectId, Long flowId, String nodeId) {
		return jobTaskService.getTaskLog(projectId, flowId, nodeId);
	}

	@GetMapping("/taskStatus")
	public BaseResponse<List<JobRunStatusVo>> loadJobStatus(Long projectId, Long flowId) {
		return jobTaskService.getTaskStatus(projectId, flowId);
	}

}
